﻿Public Class frmCapNhatDangKy

    Private Sub btnHuyDK_Click(sender As System.Object, e As System.EventArgs)
        Me.Close()
    End Sub
    Public _dkDTO As New DangKyDTO
    Public _dkBUS As New DangKyBUS
    Public _svDTO As New SinhVienDTO
    Public _svBUS As New SinhVienBUS
    Public tableLoaiNha As New DataTable
    Public tableKhuVuc As New DataTable
    Private Sub frmCapNhatDangKy_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtDienTich.Text = _dkDTO.DienTich
        txtTieuDe.Text = _dkDTO.TieuDe
        txtGiaThue.Text = _dkDTO.GiaThue
        '----------------------------------------------------------------------------------------------------
        Dim loaiNhaDTO As New LoaiNhaDTO
        Dim loaiNhaBUS As New LoaiNhaBUS
        '----------------------------------------------------------------------------------------------------
        Dim loaitinDTO As New LoaiTinDTO
        Dim loaitinBUS As New LoaiTinBUS
        '----------------------------------------------------------------------------------------------------
        Dim kvDTO As New KhuVucDTO
        Dim kvBUS As New KhuVucBUS
        '----------------------------------------------------------------------------------------------------
        tableLoaiNha = loaiNhaBUS.GetAll()
        tableKhuVuc = kvBUS.GetAll()
        '------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            If Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString()) = _dkDTO.MaLoaiNha Then
                cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
                Exit For
            End If
        Next
        cbLoaiNha.SelectedIndex = 0
        '---------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = kvDTO.TenKhuVuc Then
                cbKhuVuc.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
                Exit For
            End If
        Next
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            cbKhuVuc.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
        Next
        cbKhuVuc.SelectedIndex = 0
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
        Next

        '----------------------------------------------------------------------------------------------------
        cbSuaChua.Items.Add(_dkDTO.SucChua)
        cbSuaChua.SelectedIndex = 0
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 1 To 10
            If i <> _dkDTO.SucChua Then
                cbSuaChua.Items.Add(i.ToString())
            End If
        Next
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNamThue = 1 Then
            ckChoNamThue.Checked = True
        Else
            ckChoNamThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNuThue = 1 Then
            ckChoNuThue.Checked = True
        Else
            ckChoNuThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.ChoNauAn = 1 Then
            ckNauAn.Checked = True
        Else
            ckNauAn.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.OChungChu = 1 Then
            ckChungChu.Checked = True
        Else
            ckChungChu.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.GanCho = 1 Then
            ckGanCho.Checked = True
        Else
            ckGanCho.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.OGhep = 1 Then
            ckOGhep.Checked = True
        Else
            ckOGhep.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.Internet = 1 Then
            ckInternet.Checked = True
        Else
            ckInternet.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.TruyenHinhCap = 1 Then
            ckTruyenHinhCap.Checked = True
        Else
            ckTruyenHinhCap.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dkDTO.GanTramXeBuyt = 1 Then
            ckXeBuyt.Checked = True
        Else
            ckXeBuyt.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
    End Sub
    Private Function KiemTra() As Boolean
        If txtDienTich.Text = "" Or txtGiaThue.Text = "" Or cbSuaChua.Text = "" Or cbLoaiNha.Text = "" Or cbKhuVuc.Text = "" Or cbLoaiNha.Text = "" Then
            Return False
        End If
        Return True
    End Function
   
    Public tableDangKyID As New DataTable

    Private Sub btnCapNhat_Click(sender As System.Object, e As System.EventArgs) Handles btnCapNhat.Click
        Dim result As DialogResult = MessageBox.Show("Bạn có chắc chắn muốn thực hiện cập nhật?", "Thông báo", MessageBoxButtons.YesNo)
        If result = DialogResult.Yes Then
            If KiemTra() = True Then
                '--------------------------------------------------------------------------------------------------------------------
                For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
                    If tableLoaiNha.Rows(i)("TenLoaiNha").ToString() = cbLoaiNha.Text Then
                        _dkDTO.MaLoaiNha = Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString())
                        Exit For
                    End If
                Next
                '-----------------------------------------------------------------------------------------------------
                For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
                    If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = cbKhuVuc.Text Then
                        _dkDTO.MaKhuVucThue = Convert.ToInt32(tableKhuVuc.Rows(i)("MaKhuVuc").ToString())
                        Exit For
                    End If
                Next
                '--------------------------------------------------------------------------------------------------------
                If ckXeBuyt.Checked = True Then
                    _dkDTO.GanTramXeBuyt = 1
                Else
                    _dkDTO.GanTramXeBuyt = 0
                End If
                If ckOGhep.Checked = True Then
                    _dkDTO.OGhep = 1
                Else
                    _dkDTO.OGhep = 0
                End If
                If ckNauAn.Checked = True Then
                    _dkDTO.ChoNauAn = 1
                Else
                    _dkDTO.ChoNauAn = 0
                End If
                If ckChungChu.Checked = True Then
                    _dkDTO.OChungChu = 1
                Else
                    _dkDTO.OChungChu = 0
                End If
                If ckInternet.Checked = True Then
                    _dkDTO.Internet = 1
                Else
                    _dkDTO.Internet = 0
                End If
                If ckTruyenHinhCap.Checked = True Then
                    _dkDTO.TruyenHinhCap = 1
                Else
                    _dkDTO.TruyenHinhCap = 0
                End If
                If ckGanCho.Checked = True Then
                    _dkDTO.GanCho = 1
                Else
                    _dkDTO.GanCho = 0
                End If
                If ckChoNamThue.Checked = True Then
                    _dkDTO.ChoNamThue = 1
                Else
                    _dkDTO.ChoNamThue = 0
                End If
                If ckChoNuThue.Checked = True Then
                    _dkDTO.ChoNuThue = 1
                Else
                    _dkDTO.ChoNuThue = 0
                End If
                '--------------------------------------------------------------------------------------------------------------------
                _dkDTO.DienTich = Convert.ToSingle(txtDienTich.Text)
                _dkDTO.GiaThue = Convert.ToInt32(txtGiaThue.Text)
                _dkDTO.SucChua = Convert.ToInt32(cbSuaChua.Text)
                _dkDTO.TieuDe = txtTieuDe.Text
                '----------------------------------------------------------------------------------
               
                '-------------------------------------------------------------------------------------------------------
                _dkBUS.Update(_dkDTO)
                tableDangKyID = _dkBUS.GetItemID(_dkDTO.MaSinhVien)
                frmTrangChu.dgvDangKy.DataSource = tableDangKyID
                frmTrangChu.dgvDangKy.Show()
                Me.Close()
            End If
        End If
    End Sub

    Private Sub SimpleButton2_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton2.Click
        Me.Close()
    End Sub
End Class